﻿using System;
using System.Device.Location;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Microsoft.Phone.Controls.Maps;
using Microsoft.Phone.Controls.Maps.Platform;
using Thread = System.Threading.Thread;
using CapstoneWinPhone.Data;

namespace CapstoneWinPhone.ViewModels
{
    public class GpsModel
    {
        public GeoCoordinate FirstPosition { get; private set; }
        
        public double TotalMileage { get; private set; }
        public readonly GeoCoordinateWatcher GeoCoordinateWatcher;
        public LocationCollection locations;

        //private Service1Client proxy;

        public GpsModel()
        {
            if (DataHolder._currentUser != null)
            {
                if (DataHolder._currentUser.GPS_UpdateSpeed <= 15)
                {
                    GeoCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High) { MovementThreshold = 100 };
                }
                else
                {
                    GeoCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default) { MovementThreshold = 100 };
                }
            }
            else
            {
                GeoCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default) { MovementThreshold = 100 };
            }
        }

        public void Stop()
        {
            GeoCoordinateWatcher.Stop();
            DataHolder._currentMileageReport.newTrip(locations, "");
            locations = null;
        }
    }
}
